/*
 * key.c
 *
 *  Created on: Sep 13, 2024
 *      Author: Administrator
 */

#include "key.h"

void beep_tip()
{
	HAL_GPIO_WritePin(Beep_GPIO_Port, Beep_Pin, GPIO_PIN_SET);
	HAL_Delay(300);
	HAL_GPIO_WritePin(Beep_GPIO_Port, Beep_Pin, GPIO_PIN_RESET);
}
uint8_t get_currentKey()
{
	static uint8_t flag = 0;
	if(((HAL_GPIO_ReadPin(GPIOA, key1_Pin) == 0)||(HAL_GPIO_ReadPin(GPIOA, key2_Pin) == 0)
			||(HAL_GPIO_ReadPin(GPIOA, key3_Pin) == 0))&&(flag == 0))
	{
		HAL_Delay(20);
		if(HAL_GPIO_ReadPin(GPIOA, key1_Pin) == 0)
		{
			flag = 1;
			return 1;
		}else if(HAL_GPIO_ReadPin(GPIOA, key2_Pin) == 0)
		{
			flag = 1;
			return 2;
		}else if(HAL_GPIO_ReadPin(GPIOA, key3_Pin) == 0)
		{
			flag = 1;
			return 3;
		}
	}
	if((HAL_GPIO_ReadPin(GPIOA, key1_Pin) == 1)&&(HAL_GPIO_ReadPin(GPIOA, key2_Pin) == 1)&&(HAL_GPIO_ReadPin(GPIOA, key3_Pin) == 1)&&(flag == 1))
	{
		flag = 0;
	}
	return 0;
}
